package com.fenghongzhang.sample.recycleview2

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.fenghongzhang.sample.R
import kotlinx.android.synthetic.main.activity_sample_recycle_view2.*

/**
 * RecycleView 案例 多布局
 */
class SampleRecycleView2Activity : AppCompatActivity() {

    //延迟初始化,否则每一个方法都要加上空的判断
    private lateinit var adapter:MsgRecycleView2Adapter
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_sample_recycle_view2)

        //数据源 mutableListOf是可以添加的list集合 listOf是固定长度的list结合
        val list = mutableListOf<Msg>()
        repeat(10){
            list.add(Msg("你好",Msg.SEND))
            list.add(Msg("你好aaaa",Msg.RECEIVED))
        }

        adapter = MsgRecycleView2Adapter(list)
        val manager = LinearLayoutManager(this)
        recycleView2.layoutManager = manager
        recycleView2.adapter = adapter



    }


    companion object{
        fun launch(context: Context){
            val intent = Intent(context,SampleRecycleView2Activity::class.java)
            context.startActivity(intent)
        }
    }
}
